home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / bosco.c < prev    next >
C/C++ Source or Header  |  2000-01-09  |  1KB  |  53 lines

  1. #include "driver.h"
  2.  
  3. /* macro to convert 4-bit unsigned samples to 8-bit signed samples */
  4. #define SAMPLE_CONV4(a) (0x11*((a&0x0f))-0x80)
  5.  
  6.  
  7. static signed char *speech;    /* 24k for speech */
  8. static int channel;
  9.  
  10.  
  11.  
  12. int bosco_sh_start(const struct MachineSound *msound)
  13. {
  14.     int i;
  15.     unsigned char bits;
  16.  
  17.     channel = mixer_allocate_channel(25);
  18.     mixer_set_name(channel,"Samples");
  19.  
  20.     speech = malloc(2*memory_region_length(REGION_SOUND2));
  21.     if (!speech)
  22.         return 1;
  23.  
  24.     /* decode the rom samples */
  25.     for (i = 0;i < memory_region_length(REGION_SOUND2);i++)
  26.     {
  27.         bits = memory_region(REGION_SOUND2)[i] & 0x0f;
  28.         speech[2*i] = SAMPLE_CONV4(bits);
  29.  
  30.         bits = (memory_region(REGION_SOUND2)[i] & 0xf0) >> 4;
  31.         speech[2*i + 1] = SAMPLE_CONV4(bits);
  32.     }
  33.  
  34.     return 0;
  35. }
  36.  
  37.  
  38. void bosco_sh_stop (void)
  39. {
  40.     if (speech)
  41.         free(speech);
  42.     speech = NULL;
  43. }
  44.  
  45.  
  46. void bosco_sample_play(int offset, int length)
  47. {
  48.     if (Machine->sample_rate == 0)
  49.         return;
  50.  
  51.     mixer_play_sample(channel,speech + offset,length,4000,0);
  52. }
  53.